#ifndef __DLCD_CONFIG_H__
#define __DLCD_CONFIG_H__

#include "stm32f10x_lib.h"

//#define TIMER_IT_CHANN			 TIM_IT_CC2

#define LCD_RS_PIN               GPIO_Pin_11
#define LCD_RD_PIN               GPIO_Pin_4
#define LCD_WR_PIN               GPIO_Pin_5
#define LCD_RST_PIN              GPIO_Pin_6
#define LCD_CTRL_PINS            (LCD_RS_PIN|LCD_RD_PIN|LCD_WR_PIN)
#define LCD_CTRL_GPIO            GPIOD
#define LCD_CTRL_PERIPH          RCC_APB2Periph_GPIOD

#define LCD_CS_PIN               GPIO_Pin_7
#define LCD_CS_GPIO              GPIOD
#define LCD_CS_PERIPH            RCC_APB2Periph_GPIOD

#define LCD_D0                   GPIO_Pin_7
#define LCD_D1                   GPIO_Pin_8
#define LCD_D2                   GPIO_Pin_9
#define LCD_D3                   GPIO_Pin_10
#define LCD_D4                   GPIO_Pin_11
#define LCD_D5                   GPIO_Pin_12
#define LCD_D6                   GPIO_Pin_13
#define LCD_D7                   GPIO_Pin_14
#define LCD_DATA_PINS            (LCD_D0|LCD_D1|LCD_D2|LCD_D3|LCD_D4|LCD_D5|LCD_D6|LCD_D7)
#define LCD_DATA_GPIO            GPIOE
#define LCD_DATA_PERIPH          RCC_APB2Periph_GPIOE

//#define  GPIO_BACKLIGHT_PIN      GPIO_Pin_8


/* LCD Commands */
#define DISPLAY_ON               0xAF
#define DISPLAY_OFF              0xAE
#define START_LINE               0xC0
#define START_COLUMN             0x00
#define CLOCKWISE_OUTPUT         0xA0
#define DYNAMIC_DRIVE            0xA4
#define DUTY_CYCLE               0xA9
#define READ_MODIFY_WRITE_OFF    0xEE
#define SOFTWARE_RESET           0xE2

#define ST7732_NOP               0x00
#define ST7732_SWRESET           0x01
#define ST7732_RDDID             0x04
#define ST7732_RDDST             0x09
#define ST7732_RDDPM             0x0A
#define ST7732_RDDMADCTR         0x0B
#define ST7732_RDDCOLMOD         0x0C
#define ST7732_RDDIM             0x0D
#define ST7732_RDDSM             0x0E
#define ST7732_RDDSDR            0x0F

#define ST7732_SLPIN             0x10
#define ST7732_SLPOUT            0x11
#define ST7732_PTLON             0x12
#define ST7732_NORON             0x13

#define ST7732_INVOFF            0x20
#define ST7732_INVON             0x21
#define ST7732_GAMSET			 0x26
#define ST7732_DISPOFF           0x28
#define ST7732_DISPON            0x29
#define ST7732_CASET             0x2A
#define ST7732_RASET             0x2B
#define ST7732_RAMWR             0x2C
#define ST7732_RGBSET            0x2D
#define ST7732_RAMRD             0x2E

#define ST7732_PTLAR             0x30
#define ST7732_SCRLAR            0x33
#define ST7732_TEOFF             0x34
#define ST7732_TEON              0x35
#define ST7732_MADCTR            0x36
#define ST7732_VSCSAD            0x37
#define ST7732_IDMOFF            0x38
#define ST7732_IDMON             0x39
#define ST7732_COLMOD            0x3A

#define ST7732_RDID1             0xDA
#define ST7732_RDID2             0xDB
#define ST7732_RDID3             0xDC

#define ST7732_RGBCTR            0xB0
#define ST7732_FRMCTR1           0xB1
#define ST7732_FRMCTR2           0xB2
#define ST7732_FRMCTR3           0xB3
#define ST7732_INVCTR            0xB4
#define ST7732_RGBBPCTR          0xB5
#define ST7732_DISSET5           0xB6

#define ST7732_PWCTR1		 	 0xC0
#define ST7732_PWCTR2 		 	 0xC1
#define ST7732_PWCTR3 		 	 0xC2
#define ST7732_PWCTR4 			 0xC3
#define ST7732_PWCTR5 			 0xC4
#define ST7732_VMCTR1 			 0xC5
#define ST7732_VMOFCTR 			 0xC7

#define ST7732_WRID2             0xD1
#define ST7732_WRID3             0xD2
#define ST7732_RDID4	         0xD3
#define ST7732_NVCTR1	         0xD9
#define ST7732_NVCTR2	         0xDE
#define ST7732_NVCTR3	         0xDF

#define ST7732_GAMCTRP1          0xE0
#define ST7732_GAMCTRN1          0xE1

#define ST7732_AUTOCTRL          0xF1
#define ST7732_OSCADJ            0xF2
#define ST7732_DISPCTRL          0xF5
#define ST7732_DEFADJ            0xF6


#define V9_MADCTRVAL                0xd0     /*!< Left orientation value.             */
#define V12_MADCTRVAL               0x70     /*!< Up orientation value.        MX+MV  */
#define V3_MADCTRVAL                0x10     /*!< Right orientation value.  MY+MX     */
#define V6_MADCTRVAL                0xB0     /*!< Bottom orientation value. MY+   MV  */

const int OrientationOffsetX [] = { +0   /* V12*/,  0    /* V3*/,    0/* V6*/,  +32   /* V9*/ , +0 /*V12 at reset */};
const int OrientationOffsetY [] = { 0    /* V12*/,  0    /* V3*/,+32  /* V6*/,  0     /* V9*/ , +0 /*V12 at reset */};

typedef enum
  {
    V12=0,
    V3=1,
    V6=2,
    V9=3
} Rotate_H12_V_Match_TypeDef;


#endif // __DLCD_CONFIG_H__